package com.panfeng.xcloud.common.core.utils;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.HttpHeaders;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class TokenUtils {

    public static String getToken(HttpServletRequest request) {
        String token = StringUtils.substringAfter(request.getHeader(HttpHeaders.AUTHORIZATION), "bearer ");
        if (StringUtils.isEmpty(token)) {
            log.info(">>> 从url的queryString提取token数据 <<<");
            token = request.getParameter("token");
        }
        return token;
    }
}
